package com.example.smartgreenhouse.service.impl;

import com.example.smartgreenhouse.entity.LightIntensity;
import com.example.smartgreenhouse.entity.SoilMoisture;
import com.example.smartgreenhouse.mapper.LightIntensityMapper;
import com.example.smartgreenhouse.service.LightIntensityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class LightIntensityServiceImpl implements LightIntensityService {
    @Autowired
    private LightIntensityMapper soilMoistureMapper;
    @Override
    public Map<String, Object> saveLightIntensity(int intensity, int changeValue, float changeRate, LocalDateTime collectionTime) {
        Map<String, Object> response = new HashMap<>();
        // 创建 SoilMoisture 对象并设置数据
        LightIntensity lightIntensity= new LightIntensity();
        lightIntensity.setGreenhouse_id(1L);
        lightIntensity.setGreenhouse_id(1L);
        lightIntensity.setIntensity(intensity);  //设置当前湿度值
        lightIntensity.setIntensity_change_value(changeValue);
        lightIntensity.setIntensity_change_rate(changeRate);
        lightIntensity.setCollect_time(collectionTime);  // 设置数据采集时间
        lightIntensity.setCreate_time(LocalDateTime.now()); // 设置数据创建时间
        // 将数据插入到数据库
        soilMoistureMapper.insert(lightIntensity); // 使用 MyBatis-Plus 插入数据
        // 返回成功响应
        response.put("status", "success");
        response.put("message", "Data saved successfully.");
        response.put("timestamp", LocalDateTime.now());
        return response;
    }
}
